/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package chuiniurobot.message;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chuiniu.server.command.BaseCommand;
import java.util.HashMap;
import java.util.Map;
import org.apache.mina.core.session.IoSession;

/**
 *
 * @author zhengji
 */
public class LoginMessage extends BaseMessage {

    
    public LoginMessage(IoSession ioSession, String requestJSONStr) {
        super(ioSession, requestJSONStr);
    }

    @Override
    public void execute() {
 
        if (this.requestJSONStr == null || this.requestJSONStr.equals(""))
			return;

      JSONObject jsonObj = (JSONObject) JSON.parse(this.requestJSONStr);
      
      int code=jsonObj.getIntValue("c");
      
      int playerId=jsonObj.getIntValue("id");
      if(code==BaseCommand.SUCCESS){
          
          this.logger.debug(String.format("[%d]登录成功", playerId));
      }else{
          this.logger.debug(String.format("[%d]登录失败", playerId));
      }
      
    }
    /**
     * 返回登录json
     * @param playerID 玩家
     * @return 
     */
    public static String getLoginJson(int playerID,String deviceID){
        
        Map<String,String> map=new HashMap<String,String>();
        
        map.put("cmd", BaseCommand.LoginCommand);
        map.put("id", String.valueOf(playerID));
        map.put("did", deviceID);
        return JSON.toJSONString(map);
    }
    
}
